package com.keepsport.keepsportapi.service.impl;

import com.keepsport.keepsportapi.dao.CommunityCircleDao;
import com.keepsport.keepsportapi.dao.CommunityRemarkDao;
import com.keepsport.keepsportapi.dto.CommunityRemarkDto;
import com.keepsport.keepsportapi.entity.CommunityCircle;
import com.keepsport.keepsportapi.entity.CommunityRemark;
import com.keepsport.keepsportapi.service.intf.CommunityRemarkService;
import com.keepsport.keepsportapi.utils.BaiduCensorUtil;
import com.keepsport.keepsportapi.vo.R;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/***
 *         O
 *      _ooOoo_
 *     o8888888o
 *     88" . "88
 *     (| -_- |)
 *      O\ = /O
 *  ____/`---'\____
 *  ...............
 *  佛祖保佑  永无BUG
 *   Data:2022/7/2
 *   Author:King
 *   Description:
 */
@Service
public class CommunityRemarkServiceImpl implements CommunityRemarkService {
    @Resource
    private CommunityRemarkDao dao;
    @Resource
    private CommunityCircleDao circleDao;
    @Override
    public R selectAll() {
        return R.ok(dao.selectAll());
    }

    @Override
    public R insert(CommunityRemark remark, int token) {
        if (remark!=null){
            if (token>0){
                if(BaiduCensorUtil.textCensor(remark.getContent())){
                    remark.setUid(token);
                    remark.setCtime(new Date());
                    return R.ok(dao.insert(remark));
                }else {
                    return R.fail("你他妈犯法了你知道吗");
                }
            }
        }
        return R.fail("错误");
    }


    @Override
    public R  findAllById(int id) {
        if (id>0){
            List<CommunityRemarkDto> communityRemarkDtos = dao.selectAllById(id);
            if (communityRemarkDtos.size()!=0){
                return R.ok(communityRemarkDtos);
            }
            return R.fail("没有此信息或者此信息没评论！");
        }
        return R.fail("非法数据！");
    }


}
